//
//  DAO.m
//  QuickCure
//
//  Created by 马文星 on 16/5/2.
//  Copyright © 2016年 Demos. All rights reserved.
//
//五、inTransaction &  inDatabase 的用处
// inDatabase：     设置缓存、查询、删除
// inTransaction：(改变数据)  1创建表、2插入数据、3更新

#import "DAO.h"

@implementation DAO

- (FMDatabaseQueue *)databaseQueue{

    if (![[DataBaseManager sharedmanager] isDatabaseOpened]) {
    
        //打开数据库
        [[DataBaseManager sharedmanager] openDataBase];
        
        //获取
        _databaseQueue = [DataBaseManager sharedmanager].databaseQueue;
        
        //如果数据库有值了，就创建表
        if (_databaseQueue) {
            [DAO creatTableIfNeed];
        }
        
    }else{
    
        _databaseQueue = [DataBaseManager sharedmanager].databaseQueue;
    }

    return _databaseQueue;
}

+ (void)creatTableIfNeed{

    FMDatabaseQueue *databaseQueue = [DataBaseManager sharedmanager].databaseQueue;

    // inDataBase    打开数据库
    // inTransaction 创建表
    [databaseQueue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        //创建表
        /*!
         *  1.user_id
         *  2.true_name
         *  3.login_token
         *  4.isLogin
         */
//        NSString *sql1 = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS %@(uid INTEGER PRIMARY KEY NOT NULL,user_id TEXT,true_name TEXT)",kUserTableName];
        
        NSString *sql1 = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS %@(uid INTEGER PRIMARY KEY NOT NULL,true_name TEXT)",kUserTableName];
        
        [db executeUpdate:sql1];
        
    }];
}

/*
 
 //gender = 1;
 //mobile_number = 13269130063;
 //province_id = 370000;
 //county_id = 0;
 //age = 28;
 //user_id = 1000089;
 //true_name = 王云财;
 //weight = 156.0;
 //city_id = 0;
 //is_certify = 1;
 //address = 山东省;
 //card_type = 1;
 //easymob_password = 123456;
 //associate_id = <null>;
 //login_token = 321017f8952c7a60fd626c470dd452b9;
 //easymob_id = u1000089;
 //head_photo = http://hdkj-web1.chinacloudapp.cn:8080/res/1071000089-1451374760656.png;
 //card_number = 110109198707061355;
 //height = 185.0;

 */

@end
